package com.cms.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cms.model.dto.EchartsDto;

@Controller
public class IndexController extends BaseController {

    /**
     *跳转到主页
     * @return
     */
    @RequestMapping("/index.do")
    public String toIndexPage() {
        return "main/index";
    }

    /**
     * 跳转到欢迎页
     * @return
     */
    @RequestMapping("/home.do")
    public String toHomePage() {
        return "main/home";
    }

    /**
     * 跳转到权限不足页面
     * @return
     */
    @RequestMapping("/unauthorized.do")
    public String toUnauthorizedPage() {
        return "error/unauthorized";
    }
    
    
	 /**
     * 网站访问量,图表展示
     * @return
     */
	@RequestMapping("/ajax_echarts.do")
    @ResponseBody
    public Map<String,Object> ajaxEcharts() {
    	 Map<String,Object> result = new HashMap<String,Object>();
    	 List<EchartsDto> dtoList = new ArrayList<EchartsDto>();
    	 dtoList.add(new EchartsDto("04-12",10));
    	 dtoList.add(new EchartsDto("04-13",15));
    	 dtoList.add(new EchartsDto("04-14",20));
    	 dtoList.add(new EchartsDto("04-15",8));
    	 dtoList.add(new EchartsDto("04-16",12));
    	 dtoList.add(new EchartsDto("04-17",18));
    	 dtoList.add(new EchartsDto("04-18",30));
         if(null != dtoList && !dtoList.isEmpty()){
             List<String> xAxisDatas = new ArrayList<String>();
             List<Integer> seriesDatas = new ArrayList<Integer>();
             for (EchartsDto dto : dtoList) {
                 xAxisDatas.add(dto.getTime());
                 seriesDatas.add(dto.getCount());
             }
             result.put("xAxisData",xAxisDatas);
             result.put("seriesData",seriesDatas);
         }
         return result;
    }

}
